package com.quasar.hpatient.bean.home_inspection;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.quasar.hpatient.R;
import com.quasar.hpatient.bean.comm_album.AlbumPhotoBean;
import com.quasar.hpatient.dialog.ListDialog;

import java.util.List;

import lib.quasar.context.BaseConstant;
import lib.quasar.recycler.model.MultModel;
import lib.quasar.util.LogUtil;

public class InspectionBean {

    private String patientid = "";
    private String warn_sign = "";//是否有异常
    private String inspection_date = "";
    private int diagnose_sign = 0;//是否诊断
    private String ask_record_date = "";
    private List<EventBean> json_event = null;
    private List<ItemBean> json_inspection_data = null;
    private List<AlbumPhotoBean> json_inspection_picture = null;
    private List<DoctorBean> json_doctor = null;
    private List<SuggestBean> json_inspection_advise = null;
    private List<DiagnoseBean> json_inspection_diagnose = null;

    public boolean isDiagnose() {
        return 1 == diagnose_sign;
    }

    public String getWarn_sign() {
        return warn_sign;
    }

    public void setWarn_sign(String warn_sign) {
        this.warn_sign = warn_sign;
    }

    public List<DiagnoseBean> getJson_inspection_diagnose() {
        return json_inspection_diagnose;
    }

    public void setJson_inspection_diagnose(List<DiagnoseBean> json_inspection_diagnose) {
        this.json_inspection_diagnose = json_inspection_diagnose;
    }


    public List<SuggestBean> getJson_inspection_advise() {
        return json_inspection_advise;
    }

    public void setJson_inspection_advise(List<SuggestBean> json_inspection_advise) {
        this.json_inspection_advise = json_inspection_advise;
    }

    public String getPatientid() {
        return patientid;
    }

    public void setPatientid(String patientid) {
        this.patientid = patientid;
    }

    public String getInspection_date() {
        return inspection_date;
    }

    public void setInspection_date(String inspection_date) {
        this.inspection_date = inspection_date;
    }

    public int getDiagnose_sign() {
        return diagnose_sign;
    }

    public void setDiagnose_sign(int diagnose_sign) {
        this.diagnose_sign = diagnose_sign;
    }

    public String getAsk_record_date() {
        return ask_record_date;
    }

    public void setAsk_record_date(String ask_record_date) {
        this.ask_record_date = ask_record_date;
    }

    public List<ItemBean> getJson_inspection_data() {
        return json_inspection_data;
    }

    public void setJson_inspection_data(List<ItemBean> json_inspection_data) {
        this.json_inspection_data = json_inspection_data;
    }

    public List<AlbumPhotoBean> getJson_inspection_picture() {
        return json_inspection_picture;
    }

    public void setJson_inspection_picture(List<AlbumPhotoBean> json_inspection_picture) {
        this.json_inspection_picture = json_inspection_picture;
    }

    public List<EventBean> getJson_event() {
        return json_event;
    }

    public void setJson_event(List<EventBean> json_event) {
        this.json_event = json_event;
    }

    public List<DoctorBean> getJson_doctor() {
        return json_doctor;
    }

    public void setJson_doctor(List<DoctorBean> json_doctor) {
        this.json_doctor = json_doctor;
    }

    @Override
    public String toString() {
        return "InspectionBean{" +
                "patientid='" + patientid + '\'' +
                ", inspection_date='" + inspection_date + '\'' +
                ", ask_record_date='" + ask_record_date + '\'' +
                ", json_event=" + json_event +
                ", json_inspection_data=" + json_inspection_data +
                ", json_inspection_picture=" + json_inspection_picture +
                ", json_doctor=" + json_doctor +
                '}';
    }

    public static final class EventBean implements MultModel, Parcelable {

        private String event_datetime = "";
        private String description = "";
        private String duration_length = "";
        private String event_name = "";
        private String event_type = "";
        private String editor_type = "2";
        private String status = "1";

        public EventBean() {
        }

        protected EventBean(Parcel in) {
            event_datetime = in.readString();
            description = in.readString();
            duration_length = in.readString();
            event_name = in.readString();
            event_type = in.readString();
            editor_type = in.readString();
            status = in.readString();
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(event_datetime);
            dest.writeString(description);
            dest.writeString(duration_length);
            dest.writeString(event_name);
            dest.writeString(event_type);
            dest.writeString(editor_type);
            dest.writeString(status);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public static final Creator<EventBean> CREATOR = new Creator<EventBean>() {
            @Override
            public EventBean createFromParcel(Parcel in) {
                return new EventBean(in);
            }

            @Override
            public EventBean[] newArray(int size) {
                return new EventBean[size];
            }
        };

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getDuration_Length() {
            return duration_length;
        }

        public void setDuration_Length(String duration_length) {
            this.duration_length = duration_length;
        }

        public String getEvent_datetime() {
            return event_datetime;
        }

        public void setEvent_datetime(String event_datetime) {
            this.event_datetime = event_datetime;
        }

        public String getEvent_type() {
            return event_type;
        }

        public void setEvent_type(String event_type) {
            this.event_type = event_type;
        }

        public String getEvent_name() {
            return event_name;
        }

        public void setEvent_name(String event_name) {
            this.event_name = event_name;
        }

        public String getTime() {
            if (!TextUtils.isEmpty(event_datetime) && event_datetime.length() >= 16) {
                return event_datetime.substring(10, 16);
            } else {
                return "时间错误";
            }
        }

        public String getDay() {
            if ("1".equals(duration_length)) {
                return "1天";
            } else if ("2".equals(duration_length)) {
                return "2天";
            } else if ("3".equals(duration_length)) {
                return "3天";
            } else if ("4".equals(duration_length)) {
                return "4天";
            } else if ("5".equals(duration_length)) {
                return "5天";
            } else {
                return "5天以上";
            }
        }

        public int getPosition() {
            if ("肺部感染".equals(event_name)) {
                return 0;
            } else if ("感冒".equals(event_name)) {
                return 1;
            } else if ("发烧".equals(event_name)) {
                return 2;
            } else if ("腹泻".equals(event_name)) {
                return 3;
            } else if ("排斥反应".equals(event_name)) {
                return 4;
            } else if ("尿频".equals(event_name)) {
                return 5;
            } else if ("尿急".equals(event_name)) {
                return 6;
            } else if ("尿痛".equals(event_name)) {
                return 7;
            } else {
                return 8;
            }
        }

        public int getTextColor() {
            if (!TextUtils.isEmpty(description)) return R.color.color_bg_theme;
            else return R.color.color_font_gray60;
        }

        public String getDate() {
            if (!TextUtils.isEmpty(event_datetime) && event_datetime.length() >= 18) {
                return event_datetime.substring(0, 16);
            } else {
                return "时间错误";
            }
        }

        public String getHints() {
            return "事件：" + getDate() + " - " + event_name + " - " + getDay();
        }


        @Override
        public int getMultType() {
            if (TextUtils.isEmpty(event_datetime)) {
                return MultModel.TYPE_0;
            } else {
                return MultModel.TYPE_1;
            }
        }

        public boolean isNull() {
            return TextUtils.isEmpty(event_name);
        }

        public boolean isTypeNull() {
            return TextUtils.isEmpty(event_type);
        }
    }

    public static class DiagnoseBean implements ListDialog.ListModel {

        private String diagnose_content = "";
        private String diagnose_datetime = "";
        private int diagnose_type;
        private int diagnoseid;
        private String doctor_name = "";
        private long doctorid;
        private String patient_name = "";
        private long patientid;
        private String record_date = "";
        private String status = "";

        public String getDiagnose_content() {
            return diagnose_content;
        }

        public void setDiagnose_content(String diagnose_content) {
            this.diagnose_content = diagnose_content;
        }

        public String getDiagnose_datetime() {
            return diagnose_datetime;
        }

        public void setDiagnose_datetime(String diagnose_datetime) {
            this.diagnose_datetime = diagnose_datetime;
        }

        public int getDiagnose_type() {
            return diagnose_type;
        }

        public void setDiagnose_type(int diagnose_type) {
            this.diagnose_type = diagnose_type;
        }

        public int getDiagnoseid() {
            return diagnoseid;
        }

        public void setDiagnoseid(int diagnoseid) {
            this.diagnoseid = diagnoseid;
        }

        public String getDoctor_name() {
            return doctor_name;
        }

        public void setDoctor_name(String doctor_name) {
            this.doctor_name = doctor_name;
        }

        public long getDoctorid() {
            return doctorid;
        }

        public void setDoctorid(long doctorid) {
            this.doctorid = doctorid;
        }

        public String getPatient_name() {
            return patient_name;
        }

        public void setPatient_name(String patient_name) {
            this.patient_name = patient_name;
        }

        public long getPatientid() {
            return patientid;
        }

        public void setPatientid(long patientid) {
            this.patientid = patientid;
        }

        public String getRecord_date() {
            return record_date;
        }

        public void setRecord_date(String record_date) {
            this.record_date = record_date;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getHints() {
            return "诊断：" + doctor_name + " - " + getTime() + " - " + diagnose_content;
        }

        public String getDate() {
            if (!TextUtils.isEmpty(diagnose_datetime) && diagnose_datetime.length() >= 18) {
                return diagnose_datetime.substring(0, 10);
            } else {
                return "时间错误";
            }
        }

        @Override
        public String getIcon() {
            return null;
        }

        @Override
        public String getName() {
            return doctor_name;
        }

        @Override
        public String getTime() {
            if (!TextUtils.isEmpty(diagnose_datetime) && diagnose_datetime.length() >= 18) {
                return diagnose_datetime.substring(0, 16);
            } else {
                return "时间错误";
            }
        }

        @Override
        public String getText() {
            return "诊断结果：" + diagnose_content;
        }
    }

    public static class SuggestBean implements ListDialog.ListModel {

        private String diagnose_content = "";
        private String diagnose_datetime = "";
        private int diagnose_type;
        private int diagnoseid;
        private String doctor_name = "";
        private long doctorid;
        private String patient_name = "";
        private long patientid;
        private String record_date = "";
        private String status = "";

        public String getDiagnose_content() {
            return diagnose_content;
        }

        public void setDiagnose_content(String diagnose_content) {
            this.diagnose_content = diagnose_content;
        }

        public String getDiagnose_datetime() {
            return diagnose_datetime;
        }

        public void setDiagnose_datetime(String diagnose_datetime) {
            this.diagnose_datetime = diagnose_datetime;
        }

        public int getDiagnose_type() {
            return diagnose_type;
        }

        public void setDiagnose_type(int diagnose_type) {
            this.diagnose_type = diagnose_type;
        }

        public int getDiagnoseid() {
            return diagnoseid;
        }

        public void setDiagnoseid(int diagnoseid) {
            this.diagnoseid = diagnoseid;
        }

        public String getDoctor_name() {
            return doctor_name;
        }

        public void setDoctor_name(String doctor_name) {
            this.doctor_name = doctor_name;
        }

        public long getDoctorid() {
            return doctorid;
        }

        public void setDoctorid(long doctorid) {
            this.doctorid = doctorid;
        }

        public String getPatient_name() {
            return patient_name;
        }

        public void setPatient_name(String patient_name) {
            this.patient_name = patient_name;
        }

        public long getPatientid() {
            return patientid;
        }

        public void setPatientid(long patientid) {
            this.patientid = patientid;
        }

        public String getRecord_date() {
            return record_date;
        }

        public void setRecord_date(String record_date) {
            this.record_date = record_date;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getDate() {
            if (!TextUtils.isEmpty(diagnose_datetime) && diagnose_datetime.length() >= 18) {
                return diagnose_datetime.substring(0, 10);
            } else {
                return "时间错误";
            }
        }

        public String getHints() {
            return "建议：" + doctor_name + " - " + getTime() + " - " + diagnose_content;
        }

        @Override
        public String getIcon() {
            return null;
        }

        @Override
        public String getName() {
            return doctor_name;
        }

        @Override
        public String getTime() {
            if (!TextUtils.isEmpty(diagnose_datetime) && diagnose_datetime.length() >= 18) {
                return diagnose_datetime.substring(0, 16);
            } else {
                return "时间错误";
            }
        }

        @Override
        public String getText() {
            return "建议结果：" + diagnose_content;
        }
    }

    public static final class DoctorBean {

        private boolean isCheck;
        private long patientid;
        private long doctorid;
        private String doctor_name;
        private long relation_type;
        private String operation_datetime = "";
        private String icon = "";
        private String real_name = "";


        public boolean isCheck() {
            return isCheck;
        }

        public void setCheck(boolean check) {
            isCheck = check;
        }

        public long getPatientid() {
            return patientid;
        }

        public void setPatientid(long patientid) {
            this.patientid = patientid;
        }

        public long getDoctorid() {
            return doctorid;
        }

        public void setDoctorid(long doctorid) {
            this.doctorid = doctorid;
        }

        public long getRelation_type() {
            return relation_type;
        }

        public void setRelation_type(long relation_type) {
            this.relation_type = relation_type;
        }

        public String getOperation_datetime() {
            return operation_datetime;
        }

        public void setOperation_datetime(String operation_datetime) {
            this.operation_datetime = operation_datetime;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getReal_name() {
            return real_name;
        }

        public void setReal_name(String real_name) {
            this.real_name = real_name;
        }

        public String getDoctor_Name() {
            return doctor_name;
        }

        public void setDoctorname(String doctor_name) {
            this.doctor_name = doctor_name;
        }

        @Override
        public String toString() {
            return "DoctorBean{" +
                    "isCheck=" + isCheck +
                    ", patientid=" + patientid +
                    ", doctorid=" + doctorid +
                    ", doctor_name='" + doctor_name + '\'' +
                    ", relation_type=" + relation_type +
                    ", operation_datetime='" + operation_datetime + '\'' +
                    ", icon='" + icon + '\'' +
                    ", real_name='" + real_name + '\'' +
                    '}';
        }
    }

    /**
     * description: 化验记录, 上传的图片
     * created by kalu on 2018/4/20 11:03
     */
    public static class PictureBean {

        private String localname = BaseConstant.NULL_STR;
        private String url = BaseConstant.NULL_STR;

        public String getLocalname() {
            return localname;
        }

        public void setLocalname(String localname) {
            this.localname = localname;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }
    }

    /**
     * description: 化验记录
     * created by kalu on 2018/4/10 11:24
     */
    public static class ItemBean implements MultModel {

        private String attribute = "1"; // 状态, 1:显示(黑色), 2:显示(红色), 0:隐藏, 3:隐藏->显示
        private String flag = "1"; // 类型：1:系统大项, 0:系统小项, 3:自定义大项 4:自定义小项

        private String groupid = "";
        private String itemid = "";
        private String sortid = "";
        private String belongto = "";
        private String boundary_value = "";
        private String critical_value = "";
        private String param_value = "";
        private String dose_name = "";
        private String standard_value = "";
        private String item_value = "";
        private String item_name = "";
        private String inspection_name = "";

        /******************************************************************************************/
        public String getGroupid() {
            return groupid;
        }

        public void setGroupid(String groupid) {
            this.groupid = groupid;
        }

        public String getItemid() {
            return itemid;
        }

        public void setItemid(String itemid) {
            this.itemid = itemid;
        }

        public String getSortid() {
            return sortid;
        }

        public void setSortid(String sortid) {
            this.sortid = sortid;
        }

        public String getBelongto() {
            return belongto;
        }

        public void setBelongto(String belongto) {
            this.belongto = belongto;
        }

        public String getBoundary_value() {
            return boundary_value;
        }

        public void setBoundary_value(String boundary_value) {
            this.boundary_value = boundary_value;
        }

        public String getCritical_value() {
            return critical_value;
        }

        public void setCritical_value(String critical_value) {
            this.critical_value = critical_value;
        }

        public String getParam_value() {
            return param_value;
        }

        public void setParam_value(String param_value) {
            this.param_value = param_value;
        }

        public String getAttribute() {
            return attribute;
        }

        public void setAttribute(String attribute) {
            this.attribute = attribute;
        }

        public String getFlag() {
            return flag;
        }

        public void setFlag(String flag) {
            this.flag = flag;
        }

        public String getDose_name() {
            return dose_name;
        }

        public void setDose_name(String dose_name) {
            this.dose_name = dose_name;
        }

        public String getStandard_value() {
            return standard_value;
        }

        public void setStandard_value(String standard_value) {
            this.standard_value = standard_value;
        }

        public String getItem_value() {
            return item_value;
        }

        public void setItem_value(String item_value) {
            this.item_value = item_value;
        }

        public String getInspection_name() {
            return inspection_name;
        }

        public void setInspection_name(String inspection_name) {
            this.inspection_name = inspection_name;
        }

        public CharSequence getItem_name() {
            return item_name;
        }

        public void setItem_name(String item_name) {
            this.item_name = item_name;
        }

        /******************************************************************************************/

        public int getNameColor() {
            try {
                // 状态, 1:显示(黑色), 2:显示(红色), 0:隐藏, 3:隐藏->显示
                // 显示
                if (!BaseConstant.ONE.equals(attribute)) {
                    return R.color.color_black;
                }
                // 隐藏
                else {
                    return R.color.color_font_gray60;
                }
            } catch (Exception e) {
                LogUtil.e("", e.getMessage(), e);
                return R.color.color_font_gray60;
            }
        }

        @Override
        public int getMultType() {

            // private String attribute = "1"; // 状态, 1:显示(黑色), 2:显示(红色), 0:隐藏, 3:隐藏->显示 4
            // private String flag = "1"; // 类型：1:系统大项, 0:系统小项, 3:自定义大项 4:自定义小项


            // 大项
            if ("1".equals(flag) || "3".equals(flag)) {
                return MultModel.TYPE_0;
            }
            // 小项(隐藏)
            else if (("0".equals(attribute) && "".equals(item_value)) || ("4".equals(attribute) && "".equals(item_value))) {
                return MultModel.TYPE_1;
            }
            // 小项(显示, 普通, 定性, 尿液)
            // else if("尿常规".equals(inspection_name) && "尿液颜色".equals(item_name)) {
            else {
                return MultModel.TYPE_2;
            }
        }

        public boolean isUrine() {
            return ("尿常规".equals(inspection_name) && "尿液颜色".equals(item_name));
        }

        public boolean isStable() {
            return ("尿常规".equals(inspection_name) && !TextUtils.isEmpty(item_name) && item_name.endsWith("定性"));
        }

        public int getNormalColor() {
            return R.color.color_bg_theme;
        }

        public int getInputColor() {
            if (TextUtils.isEmpty(item_value)) {
                return R.color.color_bg_theme;
            }
            final float value = Float.parseFloat(item_value);
            if (value < getWarningMin()) {
                return R.color.color_bg_blue;
            } else if (value >= getWarningMin() && value <= getWarningMax()) {
                return R.color.color_bg_theme;
            } else if (value > getWarningMax()) {
                return R.color.color_bg_peach;
            } else {
                return R.color.color_bg_theme;
            }
        }

        // // 类型：1:系统大项, 0:系统小项, 3:自定义大项 4:自定义小项
        public boolean isBig() {
            return "1".equals(flag) || "3".equals(flag);
        }

        public boolean canDelete() {
            return !"1".equals(flag) || !"0".equals(flag) || !"3".equals(flag);
        }

        public float getInputMax() {
            try {
                if (!TextUtils.isEmpty(boundary_value)) {
                    final String[] split = boundary_value.split("-");
                    if (split.length > 1) {
                        return Float.parseFloat(split[1]);
                    } else {
                        return -1f;
                    }
                } else {
                    return -1f;
                }
            } catch (Exception e) {
                LogUtil.e("ItemBean", "异常值3");
                return -1f;
            }
        }

        public float getInputMin() {
            try {
                if (!TextUtils.isEmpty(boundary_value)) {
                    final String[] split = boundary_value.split("-");
                    if (split.length > 1) {
                        return Float.parseFloat(split[0]);
                    } else {
                        return 0f;
                    }
                } else {
                    return 0f;
                }
            } catch (Exception e) {
                LogUtil.e("ItemBean", "异常值3");
                return 0f;
            }
        }

        public float getWarningMin() {
            try {
                if (!TextUtils.isEmpty(standard_value)) {
                    final String[] split = standard_value.split("-");
                    if (split.length > 0) {
                        return Float.parseFloat(split[0]);
                    } else {
                        return 0f;
                    }
                } else {
                    return 0f;
                }

            } catch (Exception e) {
                LogUtil.e("ItemBean", "异常值2");
                return -1f;
            }
        }

        public float getWarningMax() {
            try {
                if (!TextUtils.isEmpty(standard_value)) {
                    final String[] split = standard_value.split("-");
                    if (split.length > 1) {
                        return Float.parseFloat(split[1]);
                    } else {
                        return 0f;
                    }

                } else {
                    return 0f;
                }

            } catch (Exception e) {
                LogUtil.e("ItemBean", "异常值");
                return -1f;
            }
        }

        public boolean isLessthanMins() {

            if (TextUtils.isEmpty(item_value))
                return false;

            try {
                final float value = Float.parseFloat(item_value);
                return value < getInputMin();
            } catch (Exception e) {
                // LogUtil.e("isLessthanMins", e.getMessage(), e);
                return true;
            }
        }

        public boolean isWarnings() {

            if (TextUtils.isEmpty(item_value))
                return false;

            try {
                final float value = Float.parseFloat(item_value);
                return value < getWarningMin() || value > getWarningMax();
            } catch (Exception e) {
                // LogUtil.e("isLessthanMins", e.getMessage(), e);
                return true;
            }
        }
    }
}
